<template>
  <div>
    <a-modal title='客户银行选择(可通过双击行选择)' :width='1000'  :dialog-style="{ top: '10px' }" :visible='visible' :confirmLoading='loading' :footer='null' @ok='handleSubmit' @cancel='close'>
      <f-table ref='table' rowKey='customBankId' v-if='visible' @dblclick='dblclick' :columns='columns' :multiple='false' :showRadio='true' :operator='operator' :params='queryParam' :api='api.customBank' @onSelectChange='onSelectChange'>
       <span slot='action' slot-scope='text, record'>
         <template>
          <a @click='editBank(record)'>编辑</a>
        </template>
      </span>
      </f-table>
    </a-modal>
    <a-modal title='添加银行账户' :visible='bankModal' width='700px' @cancel='handleCancel' @ok='bankSubmit'>
      <f-form ref='form' :action='api.customBank' :form-key='this.formItem.customBankId'>
        <f-form-item label='银行名称' name='bankName' :required='true' :value='formItem.bankName' />
        <f-form-item label='银行卡号' name='bankNo' :required='true' :value='formItem.bankNo' />
        <f-form-item label='收款人' name='userName' :required='true' :value='formItem.userName' />
        <f-form-item label='备注' name='remark' :value='formItem.remark' />
      </f-form>
    </a-modal>
  </div>
</template>
<script>
import api from "../js/api"

export default {
  name: "SelectCustomBankModal",
  props: {},
  data() {
    let operator = []
    operator.push({
      name: "添加",
      icon: "plus",
      that: this,
      handler: (table) => {
        this.bankModal = true
      }
    })
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      selectedRowKeys: [],
      bankModal: false,
      formItem: {
        customBankId: "",
        bankName: "",
        userName: "",
        bankNo: "",
        remark: ""
      },
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {},

      // 表头
      columns: [
        {
          title: "收款人",
          align: "center",
          width: "120px",
          dataIndex: "userName"
        },
        {
          title: "银行名称",
          align: "center",
          width: "120px",
          dataIndex: "bankName"
        },
        {
          title: "账号",
          align: "center",
          width: "100px",
          dataIndex: "bankNo"
        },
        {
          title: "备注",
          align: "center",
          width: "100px",
          dataIndex: "remark"
        },
        {
          title: "操作",
          align: "center",
          width: "100px",
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  methods: {
    open(params) {
      this.queryParam = params
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    dblclick(record, event) {
      let selectedRowKeys = []
      let selectedRows = []
      selectedRowKeys.push(record.customBankId)
      selectedRows.push(record)
      this.$emit("onSelectChange", selectedRowKeys, selectedRows)
      this.close()
    },
    handleSubmit() {
      this.$emit("onSelectChange", this.selectedRowKeys, this.selectedRows)
      this.close()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    editBank(record) {
      this.formItem = record
      this.bankModal = true
    },
    bankSubmit() {
      this.$refs.form.submit({ customId: this.queryParam.customId }, this.handleCancel)
    },
    handleCancel() {
      this.bankModal = false
    }
  },
  created() {
  },
  components: {}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
